using System;
using Slaks.Graphs.Algorithms.DistanceAlgorithm;

namespace Slaks.Graphs.Algorithms.ExperimentalDistances
{
	public class MCSSubgraphVertexEdgeFrequency : GraphDistanceBase
	{
        public MCSSubgraphVertexEdgeFrequency()
            : base()
        {
        }

        public MCSSubgraphVertexEdgeFrequency(Graph one, Graph two) 
            : base ( one, two )
        {
        }				

		public override double GetDistance()
		{
			double mcsRegular = new DistMCS4VertexEdgeFrequency(one, two).GetDistance();

			Graph maxCommonSubgraph = (one.GetMCS(two));
			//double mcsEdgeFrequency = maxCommonSubgraph.GetEdgeFrequency();
			double mcsVertexFrequency = maxCommonSubgraph.GetVertexFrequency();

			//double graphSizeOneEdgeCount = one.GetEdgeCount();
			double graphSizeOneVertexFrequency = one.GetVertexFrequency();
			//double graphSizeTwoEdgeCount = two.GetEdgeCount();
			double graphSizeTwoVertexFrequency = two.GetVertexFrequency();

			double graphSizeOne = one.GetGraphSizeVertexEdgeFrequency;
			double graphSizeTwo = two.GetGraphSizeVertexEdgeFrequency;


			if (mcsVertexFrequency == graphSizeOneVertexFrequency)
				return graphSizeOneVertexFrequency/graphSizeTwoVertexFrequency;
			if (mcsVertexFrequency == graphSizeTwoVertexFrequency)
				return graphSizeTwoVertexFrequency/graphSizeOneVertexFrequency;
			if (mcsVertexFrequency*2 > graphSizeOneVertexFrequency && graphSizeOneVertexFrequency < graphSizeTwoVertexFrequency)
			{
				//return 1 - graphSizeOneVertexCount /Math.Max(graphSizeOne, graphSizeTwo);
				return 1 - graphSizeOne/Math.Max(graphSizeOne, graphSizeTwo);
				//return 1 - graphSizeOneVertexCount / graphSizeTwoVertexCount;
			}
			else if (mcsVertexFrequency*2 > graphSizeTwoVertexFrequency && graphSizeOneVertexFrequency > graphSizeTwoVertexFrequency)
			{
				//return 1 - graphSizeTwoVertexCount /Math.Max(graphSizeOne, graphSizeTwo);
				return 1 - graphSizeTwo/Math.Max(graphSizeOne, graphSizeTwo);
				//return 1 - graphSizeTwoVertexCount / graphSizeOneVertexCount;
			}
			return mcsRegular;
		}


	}
}